//
//  DARateNumberAndRateMessage.m
//  DAKnowledge
//
//  Created by DreamArts on 16/6/7.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DARateNumberAndRateMessage.h"
#import "DALabel.h"
#import "Masonry.h"
#import "Utility.h"
#import "DAHeader.h"
@interface DARateNumberAndRateMessage (){

    NSString *rateNumber;
}
@end

@implementation DARateNumberAndRateMessage

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:backGroundColor];
        self.layer.cornerRadius = 5;
        NSString *titleStr = NSLocalizedString(@"inputYourBookComments", nil);
        
        self.titleLabel = [[DALabel alloc]init];
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        [self.titleLabel setText:titleStr fitToContent:YES];
        [self addSubview:self.titleLabel];
        
        self.textView = [[UITextView alloc]init];
        self.textView.layer.cornerRadius = 5;
        [self addSubview:self.textView];
        
        NSString *rateStr = NSLocalizedString(@"ToScoreThisBook", nil);
        self.rateNumLabel = [[DALabel alloc]init];
        [self.rateNumLabel setText:rateStr fitToContent:YES];
        self.rateNumLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:self.rateNumLabel];
        
       
        self.rateNum1 = [[UIImageView alloc]init];
        self.rateNum1.image = [UIImage imageNamed:@"rate1@3x"];
        [self addSubview:self.rateNum1];
        self.rateNum1.userInteractionEnabled = YES;
        self.rateNum1.tag = 1000;
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeRateNumber:)];
        [self.rateNum1 addGestureRecognizer:tap1];
       
        self.rateNum2 =[[UIImageView alloc]init];
        self.rateNum2.image = [UIImage imageNamed:@"rate1@3x"];
        [self addSubview:self.rateNum2];
        self.rateNum2.userInteractionEnabled = YES;
        self.rateNum2.tag = 1001;
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeRateNumber:)];
        [self.rateNum2 addGestureRecognizer:tap2];
        
        
        self.rateNum3 = [[UIImageView alloc]init];
        self.rateNum3.image = [UIImage imageNamed:@"rate1@3x"];
        [self addSubview:self.rateNum3];
        self.rateNum3.userInteractionEnabled = YES;
        self.rateNum3.tag = 1005;
        UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeRateNumber:)];
        [self.rateNum3 addGestureRecognizer:tap3];
        
        
        self.rateNum4 = [[UIImageView alloc]init];
        self.rateNum4.image = [UIImage imageNamed:@"rate1@3x"];
        [self addSubview:self.rateNum4];
        self.rateNum4.userInteractionEnabled = YES;
        self.rateNum4.tag = 1003;
        UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeRateNumber:)];
        [self.rateNum4 addGestureRecognizer:tap4];
        
        self.rateNum5 = [[UIImageView alloc]init];
        self.rateNum5.image = [UIImage imageNamed:@"rate1@3x"];
        [self addSubview:self.rateNum5];
        self.rateNum5.userInteractionEnabled = YES;
        self.rateNum5.tag = 1004;
        UITapGestureRecognizer *tap5  = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeRateNumber:)];
        [self.rateNum5 addGestureRecognizer:tap5];
        
        self.closeImage = [[UIImageView alloc]init];
        self.closeImage.image = [UIImage imageNamed:@"close"];
        [self addSubview:self.closeImage];
        
        self.closeView = [[UIView alloc]init];
        UITapGestureRecognizer *tapClose = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickCloseView:)];
        [self.closeView addGestureRecognizer:tapClose];
        [self addSubview:self.closeView];
        
        NSString *backtr = NSLocalizedString(@"backBook", nil);
        self.sendMessageButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.sendMessageButton.layer.cornerRadius = 5;
        self.sendMessageButton.backgroundColor = [UIColor supportGreenColor];
        [self.sendMessageButton setTitle:backtr forState:UIControlStateNormal];
        [self.sendMessageButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self addSubview:self.sendMessageButton];
        self.sendMessageButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.sendMessageButton addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
        
        rateNumber = @"5";

    }
    return self;
}

- (void)layoutSubviews{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        //make.center.mas_equalTo(self.center.x);
        make.left.mas_equalTo(20);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(20);
    }];
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(10);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(130);
    }];
    [self.rateNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.textView.mas_bottom).offset(10);
        make.left.mas_equalTo(self.textView);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(20);
    }];
    [self.rateNum1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.textView.mas_bottom).offset(10);
        make.left.mas_equalTo(self.rateNumLabel.mas_right).offset(10);
        make.width.height.mas_equalTo(20);
    }];
    [self.rateNum2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.rateNum1);
        make.left.mas_equalTo(self.rateNum1.mas_right).offset(6);
        make.width.height.mas_equalTo(self.rateNum1);
    }];
    [self.rateNum3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.rateNum1);
        make.left.mas_equalTo(self.rateNum2.mas_right).offset(6);
        make.width.height.mas_equalTo(20);
    }];
    [self.rateNum4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.rateNum1);
        make.left.mas_equalTo(self.rateNum3.mas_right).offset(6);
        make.width.height.mas_equalTo(20);
    }];
    [self.rateNum5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.rateNum1);
        make.left.mas_equalTo(self.rateNum4.mas_right).offset(6);
        make.width.height.mas_equalTo(20);
    }];
    
    [self.sendMessageButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.rateNumLabel.mas_bottom).offset(20);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(30);
    }];
    
    
    [self.closeImage  mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(5);
        make.right.mas_equalTo(-8);
        make.width.height.mas_equalTo(20);
    }];
    
    [self.closeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.right.mas_equalTo(0);
        make.width.height.mas_equalTo(40);
    }];
    
}
- (void)changeRateNumber:(UITapGestureRecognizer *)tap{
    
    if (tap.view.tag == 1000) {
            self.rateNum1.image =[UIImage imageNamed:@"rate1@3x"];
            self.rateNum2.image = [UIImage imageNamed:@"rate0@3x"];
            self.rateNum3.image = [UIImage imageNamed:@"rate0@3x"];
            self.rateNum4.image = [UIImage imageNamed:@"rate0@3x"];
            self.rateNum5.image = [UIImage imageNamed:@"rate0@3x"];
        rateNumber = @"1";
    }
    if (tap.view.tag == 1001) {
        self.rateNum1.image =[UIImage imageNamed:@"rate1@3x"];
        self.rateNum2.image = [UIImage imageNamed:@"rate1@3x"];
        self.rateNum3.image = [UIImage imageNamed:@"rate0@3x"];
        self.rateNum4.image = [UIImage imageNamed:@"rate0@3x"];
        self.rateNum5.image = [UIImage imageNamed:@"rate0@3x"];
        
        rateNumber = @"2";
    }
    if (tap.view.tag == 1005) {
        self.rateNum1.image =[UIImage imageNamed:@"rate1@3x"];
        self.rateNum2.image = [UIImage imageNamed:@"rate1@3x"];
        self.rateNum3.image = [UIImage imageNamed:@"rate1@3x"];
        self.rateNum4.image = [UIImage imageNamed:@"rate0@3x"];
        self.rateNum5.image = [UIImage imageNamed:@"rate0@3x"];
        rateNumber = @"3";
    }
    if (tap.view.tag == 1003) {
        self.rateNum1.image =[UIImage imageNamed:@"rate1@3x"];
        self.rateNum2.image = [UIImage imageNamed:@"rate1@3x"];
        self.rateNum3.image = [UIImage imageNamed:@"rate1@3x"];
        self.rateNum4.image = [UIImage imageNamed:@"rate1@3x"];
        self.rateNum5.image = [UIImage imageNamed:@"rate0@3x"];
        rateNumber = @"4";
    }
    if (tap.view.tag == 1004) {
        self.rateNum1.image =[UIImage imageNamed:@"rate1@3x"];
        self.rateNum2.image = [UIImage imageNamed:@"rate1@3x"];
        self.rateNum3.image = [UIImage imageNamed:@"rate1@3x"];
        self.rateNum4.image = [UIImage imageNamed:@"rate1@3x"];
        self.rateNum5.image = [UIImage imageNamed:@"rate1@3x"];
        rateNumber = @"5";
    }
    
}
- (void)clickButton:(UIButton *)btn{

   [self.delegate backBookWithRateNumber:rateNumber];

}

- (void)clickCloseView:(UITapGestureRecognizer *)tap{
    [self.delegate clickRateMessageViewCloseView];
}







/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
